package com.qcxk.yuqian.rtu.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.qcxk.yuqian.rtu.controller.model.query.RtuDTO;
import com.qcxk.yuqian.rtu.controller.model.query.RtuVO;
import com.qcxk.yuqian.rtu.entity.Rtu;
import com.qcxk.yuqian.rtu.mapper.RtuMapper;
import com.qcxk.yuqian.rtu.service.IRtuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import com.qcxk.yuqian.system.component.QueryWrapperConverter;

import java.util.List;

/**
 * @auther lp
 * @create 2021-11-15 03:21:45
 * @describe 服务实现类
 */
@Service
public class RtuServiceImpl extends ServiceImpl<RtuMapper, Rtu> implements IRtuService {
    @Autowired
    private RtuMapper rtuMapper;

    @Override
    public Page queryRtuPage(Page page, Rtu rtu) {

        QueryWrapper<Rtu> rtuQueryWrapper = new QueryWrapper<>();
        QueryWrapperConverter.converter(rtuQueryWrapper, rtu);

        rtuQueryWrapper.orderByDesc("ctime");
        rtuMapper.selectRtuPage(page, rtu);
        return page;
    }

    @Override
    public Page queryRtuStatusPage(Page page, Rtu rtu) {
        rtuMapper.selectStatusPage(page, rtu);
        return page;
    }

    @Override
    public Rtu findRtu(String  rtuNo) {
        return rtuMapper.findRtu(rtuNo);
    }

    @Override
    public int addRtu(Rtu rtu) {
        return rtuMapper.add(rtu);
    }

    @Override
    public Rtu findRtuById(Long id) {
        return rtuMapper.findRtuById(id);
    }

    @Override
    public List<RtuDTO> getRtuAddress(Rtu rtu) {
        return rtuMapper.findAddress(rtu);
    }

    @Override
    public List<RtuVO> findRTUList(RtuVO dto) {
        return rtuMapper.selectRtuList(dto);
    }

    @Override
    public boolean deleteById(Rtu rtu) {
        int re = rtuMapper.deleteById(rtu.getId());
        return re == 1 ? true : false;
    }
}
